<?php
include('../library/adodb5/adodb.inc.php');
include( '../config/Helper.php');

class Config{
	const PATH_REAL	  =	"";
	const BASE_URL	  =	"";
	const ERROR_PAGE  =	"404.php";
	const PATH_CTRL	  =	"../controller/";
	const PATH_FILE	  =	"../files/";
	const APP_NAME	  =	"MiColmena.cl";
	const APP_FASE	  =	"(desarrollo)";
	const APP_BDNAME  =	"micol";
	const USER_DOMAIN = "@micolmena.cl";
	const USER_DEVELOPER = true;
		
	const TIPO_SUPERADMIN = 1;
	const TIPO_ADMIN = 10;
	const TIPO_OTROS = 20;
	const TIPO_SIN_ROL = 777;

	static $_instance; 

	static public function switchs($aParams){
		$sController = (!isset($aParams['controller']))?'index':$aParams['controller'];
		$aItems = self::menuItems();
		$aItems[$sController] = (empty($aItems[$sController]))? 'HomeController' : $aItems[$sController]; 
		$sInclude = self::PATH_CTRL.$aItems[$sController].'.php';
		include_once $sInclude;
		if(isset($aParams['action']))
		{
			$oModel = $aItems[$sController];
			$oModelo = new $oModel();	

			@session_start();
			$oModelo->index($aParams);	
		}					
	}
		
	static public function menuItems()
	{
		$aMenu['home']='HomeController';
		$aMenu['apiario']='ApiarioController';
		$aMenu['colmena']='ColmenaController';
		$aMenu['costo']='CostoController';


		return $aMenu; 
	}
		
	static public function dbExt()
	{
		$conn = ADONewConnection('mysql');
		$conn->NConnect('localhost','root','',self::APP_BDNAME);
		$conn->execute("SET NAMES utf8");
		$conn->SetFetchMode(ADODB_FETCH_ASSOC);			
		return $conn;
	}
	
	static public function insertFormat($aData)
	{
		$sTvalue="";
		$sVvalue="";
		$aTs=array();
		$sQ="";

		foreach($aData as $iK=>$mDat)
		{
			if($mDat['value']!=''){
				$sTvalue.=$mDat['name'].",";
				$sVvalue.='"'.$mDat['value'].'",';
				$aTs[]=$mDat['value'];
				$sQ.="?".",";
			}
		}
		$sTvalue=substr($sTvalue,0,-1);
		$sVvalue=substr($sVvalue,0,-1);
		$sQ=substr($sQ,0,-1);
		$aResul=array($sTvalue,$sVvalue,$aTs,$sQ);
		return $aResul;
	}

	static public function selectFormat($aData)
	{	
		foreach($aData as $iK=>$mDat)
		{
			if(!empty($mDat['value'])){
				$aDef[$mDat['name']]=$mDat['value'];
			}
		}		

		$sSql = ' WHERE ';
		
		foreach($aDef as $iK=>$mDat)
		{
			$sSql .=" $iK = '$mDat' AND ";
		}
		
		$sSql=substr($sSql,0,-4);
		return $sSql;			
	}

	static public function validaUser($sUser,$sPass){
		$resultado = (self::USER_DEVELOPER)?1:0;
		return $resultado; 		
	}
	
		
	static public function menu()
	{
		include_once '../views/menu.php';
	}
}

?>